import { ExpeditionOrder } from './../../models/expeditionOrder';
import { Subscription } from 'rxjs';
import { expeditionOrdersService } from './../../services/expeditionOrders';
import { Component, OnInit, OnDestroy } from '@angular/core';

@Component({
    selector: 'finished',
    templateUrl: './finished.component.html',
    styleUrls: ['./finished.component.scss']

})

export class FinishedComponent implements OnInit, OnDestroy {
    subscriptions: Array<Subscription> = [];
    private finishedList:Array<ExpeditionOrder>;

    public async ngOnInit() {
        const subscription = expeditionOrdersService.getExpeditionOrders().subscribe(orders => {
            this.finishedList = orders.sort((a, b) => b.deliveryBeginTime - a.deliveryBeginTime); 
        })
        this.subscriptions.push(subscription);
        expeditionOrdersService.notify();
    }

    ngOnDestroy() {
        this.subscriptions.forEach(subscription => subscription.unsubscribe())
    }

}